package com.settlement.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.common.result.PageResult;
import com.settlement.system.common.result.Result;
import com.settlement.system.model.entity.SysImportErrorDetail;
import com.settlement.system.model.query.ImportErrorDetailPageQuery;
import com.settlement.system.service.SysImportErrorDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author huangrensen
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/api/v1/importErrorDetail")
@RequiredArgsConstructor
public class SysImportErrorDetailController {

    private final SysImportErrorDetailService importErrorDetailService;

    @Operation(summary = "导入日志详情分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<SysImportErrorDetail> getStorePage(@ParameterObject ImportErrorDetailPageQuery queryParams
    ) {
        Page<SysImportErrorDetail> result = importErrorDetailService.getImportErrorDetailPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "重新推送一个消息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/pushOne")
    @PreAuthorize("@ss.hasPerm('sys:logRecord:pushOne')")
    public Result<?> pushOne(@RequestBody @Valid SysImportErrorDetail detail) {
        importErrorDetailService.pushOne(detail);
        return Result.success();
    }

    @Operation(summary = "重新推送消息", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/rePush")
    @PreAuthorize("@ss.hasPerm('sys:logRecord:rePush')")
    public Result<?> rePush(@RequestParam("ids") String ids) {
        importErrorDetailService.rePush(ids);
        return Result.success();
    }

    @Operation(summary = "推送所有", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/rePushAll")
    @PreAuthorize("@ss.hasPerm('sys:logRecord:rePushAll')")
    public Result<?> rePushAll() {
        importErrorDetailService.rePushAll();
        return Result.success();
    }
}
